package com.jyu.hakkatranslation.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {

    /**显示相对地址*/
    @Value("${file.upload.path.relative}")
    private String fileRelativePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //动态获取当前项目的路径
        String projectPath = System.getProperty("user.dir");
        //File.separator相当于路径中的/  这能保证在任何系统中都不报错,如果写成/windows下不报错但是在linux下可能会报错
        String destDir = projectPath + File.separator +"src"+File.separator+"main"+ File.separator +"resources"+File.separator+"static"+ File.separator+"mp3"+File.separator;

        registry.addResourceHandler(fileRelativePath).
                addResourceLocations("file:/" + destDir);
    }

}
